#coding=utf-8
from flask import Flask
from flask import jsonify
import jieba
import jieba.analyse
import jieba.posseg
import sys
import tag.keyword
reload(sys)
sys.setdefaultencoding('utf-8')
app = Flask(__name__)
key = tag.keyword.Keyword('./cfg.json')

@app.route('/title/<title>')
def get(title):
    tags =  jieba.analyse.extract_tags(title, withWeight=True)
    for item in tags:
        ret = key.get(item[0].strip())
        if ret!=None:
            break
    if ret == None:
        return jsonify(code=0)
    else:
        return jsonify(code=1,tag=ret)

if __name__ == '__main__':
    app.run()